package com.baige.api.app.controller;

import com.baige.api.app.sdk.request.UserAddressRequest;
import com.baige.api.app.sdk.response.UserAddressResponse;
import com.baige.common.core.BaseResponse;
import com.baige.common.core.MsgResponse;
import com.baige.common.core.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

/**
 * 用户地址接口
 * @author wulg
 * @date 2018/12/13.
 */
@Api(value = "UserAddressController", description = "用户地址接口", produces = org.springframework.http.MediaType.APPLICATION_JSON_VALUE)
@RestController
@RequestMapping("/api/rest/user/address")
public class UserAddressController
{
    private static final Logger logger = LoggerFactory.getLogger(UserAddressController.class);


    /**
     * 获取用户地址列表
     * @param userId 用户id
     * @return Result<UserAddressResponse>
     */
    @GetMapping(value = "/v1/{userId}/list", produces = {"application/json;charset=UTF-8", "application/xml;charset=UTF-8"})
    @ApiOperation(value = "获取用户地址列表", notes = "获取用户地址列表", httpMethod = "GET", produces = org.springframework.http.MediaType.APPLICATION_JSON_VALUE)
    public Result<List<UserAddressResponse>> getUserAddressList(@PathVariable("userId") String userId) {
        return null;
    }

    /**
     * 用户地址详情
     *
     * @param addressId 地址id
     * @return Result<UserAddressResponse>
     */
    @GetMapping(value = "/v1/{addressId}", produces = {"application/json;charset=UTF-8", "application/xml;charset=UTF-8"})
    @ApiOperation(value = "用户地址详情", notes = "用户地址详情", httpMethod = "GET", produces = org.springframework.http.MediaType.APPLICATION_JSON_VALUE)
    public Result<UserAddressResponse> getUserAddress(@PathVariable("addressId") String addressId) {
        return null;
    }

    /**
     * 用户设置默认地址
     *
     * @param addressId 地址id
     * @return Result<MsgResponse>
     */
    @PutMapping(value = "/v1/defaultAddress/{addressId}", produces = {"application/json;charset=UTF-8", "application/xml;charset=UTF-8"})
    @ApiOperation(value = "用户设置默认地址", notes = "用户设置默认地址", httpMethod = "PUT", produces = org.springframework.http.MediaType.APPLICATION_JSON_VALUE)
    public Result<MsgResponse> modifyUserDefaultAddress(@PathVariable("addressId") String addressId) {
        return null;
    }

    /**
     * 删除地址
     *
     * @param addressId 地址id
     * @return Result<MsgResponse>
     */
    @DeleteMapping(value = "/v1/{addressId}", produces = {"application/json;charset=UTF-8", "application/xml;charset=UTF-8"})
    @ApiOperation(value = "删除地址", notes = "删除地址", httpMethod = "DELETE", produces = org.springframework.http.MediaType.APPLICATION_JSON_VALUE)
    public Result<MsgResponse> deleteUserAddress(@PathVariable("addressId") String addressId) {
        return null;
    }

    /**
     * 用户修改地址
     *
     * @param requestParams 请求参数
     * @param addressId     地址id
     * @param bindingResult 参数校验
     * @return Result<UserAddressResponse>
     */
    @PutMapping(value = "/v1/{addressId}", produces = {"application/json;charset=UTF-8", "application/xml;charset=UTF-8"})
    @ApiOperation(value = "用户修改地址", notes = "用户修改地址", httpMethod = "PUT", produces = org.springframework.http.MediaType.APPLICATION_JSON_VALUE)
    public Result<UserAddressResponse> modifyUserAddress(@Valid @RequestBody UserAddressRequest requestParams, @PathVariable("addressId") String addressId, BindingResult bindingResult) {
        if (bindingResult.hasErrors()) {
            logger.error("用户修改地址参数传递错误,message:{}", bindingResult.getFieldErrors().get(0).getDefaultMessage());
            return BaseResponse.newErrorParamReturnObject(bindingResult.getFieldErrors().get(0).getDefaultMessage());
        }
        return null;
    }

    /**
     * 用户新增地址
     *
     * @param requestParams 请求参数
     * @param userId        用户id
     * @param bindingResult 参数校验
     * @return Result<UserAddressResponse>
     */
    @PostMapping(value = "/v1/{userId}", produces = {"application/json;charset=UTF-8", "application/xml;charset=UTF-8"})
    @ApiOperation(value = "用户新增地址", notes = "用户新增地址", httpMethod = "POST", produces = org.springframework.http.MediaType.APPLICATION_JSON_VALUE)
    public Result<UserAddressResponse> addUserAddress(@Valid @RequestBody UserAddressRequest requestParams, @PathVariable("userId") String userId, BindingResult bindingResult) {
        if (bindingResult.hasErrors()) {
            logger.error("用户新增地址参数传递错误,message:{}", bindingResult.getFieldErrors().get(0).getDefaultMessage());
            return BaseResponse.newErrorParamReturnObject(bindingResult.getFieldErrors().get(0).getDefaultMessage());
        }
        return null;
    }
}
